using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Impact.Model.Objects
{
	/// <summary>
	/// Strongly-typed collection for the Photo class.
	/// </summary>
    [Serializable]
	public partial class PhotoCollection : ActiveList<Photo, PhotoCollection>
	{	   
		public PhotoCollection() {}
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the impact_Photos table.
	/// </summary>
	[Serializable]
	public partial class Photo : ActiveRecord<Photo>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Photo()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Photo(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Photo(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Photo(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("impact_Photos", TableType.Table, DataService.GetInstance("ImpactProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarPhotoID = new TableSchema.TableColumn(schema);
				colvarPhotoID.ColumnName = "PhotoID";
				colvarPhotoID.DataType = DbType.Int32;
				colvarPhotoID.MaxLength = 0;
				colvarPhotoID.AutoIncrement = true;
				colvarPhotoID.IsNullable = false;
				colvarPhotoID.IsPrimaryKey = true;
				colvarPhotoID.IsForeignKey = false;
				colvarPhotoID.IsReadOnly = false;
				colvarPhotoID.DefaultSetting = @"";
				colvarPhotoID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPhotoID);
				
				TableSchema.TableColumn colvarGalleryID = new TableSchema.TableColumn(schema);
				colvarGalleryID.ColumnName = "GalleryID";
				colvarGalleryID.DataType = DbType.Int32;
				colvarGalleryID.MaxLength = 0;
				colvarGalleryID.AutoIncrement = false;
				colvarGalleryID.IsNullable = false;
				colvarGalleryID.IsPrimaryKey = false;
				colvarGalleryID.IsForeignKey = true;
				colvarGalleryID.IsReadOnly = false;
				colvarGalleryID.DefaultSetting = @"";
				
					colvarGalleryID.ForeignKeyTableName = "impact_PhotoGalleries";
				schema.Columns.Add(colvarGalleryID);
				
				TableSchema.TableColumn colvarFilename = new TableSchema.TableColumn(schema);
				colvarFilename.ColumnName = "Filename";
				colvarFilename.DataType = DbType.AnsiString;
				colvarFilename.MaxLength = 300;
				colvarFilename.AutoIncrement = false;
				colvarFilename.IsNullable = false;
				colvarFilename.IsPrimaryKey = false;
				colvarFilename.IsForeignKey = false;
				colvarFilename.IsReadOnly = false;
				colvarFilename.DefaultSetting = @"";
				colvarFilename.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFilename);
				
				TableSchema.TableColumn colvarCaption = new TableSchema.TableColumn(schema);
				colvarCaption.ColumnName = "Caption";
				colvarCaption.DataType = DbType.AnsiString;
				colvarCaption.MaxLength = 500;
				colvarCaption.AutoIncrement = false;
				colvarCaption.IsNullable = true;
				colvarCaption.IsPrimaryKey = false;
				colvarCaption.IsForeignKey = false;
				colvarCaption.IsReadOnly = false;
				colvarCaption.DefaultSetting = @"";
				colvarCaption.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCaption);
				
				TableSchema.TableColumn colvarTimestamp = new TableSchema.TableColumn(schema);
				colvarTimestamp.ColumnName = "Timestamp";
				colvarTimestamp.DataType = DbType.DateTime;
				colvarTimestamp.MaxLength = 0;
				colvarTimestamp.AutoIncrement = false;
				colvarTimestamp.IsNullable = false;
				colvarTimestamp.IsPrimaryKey = false;
				colvarTimestamp.IsForeignKey = false;
				colvarTimestamp.IsReadOnly = false;
				colvarTimestamp.DefaultSetting = @"";
				colvarTimestamp.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTimestamp);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["ImpactProvider"].AddSchema("impact_Photos",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("PhotoID")]
		[Bindable(true)]
		public int PhotoID 
		{
			get { return GetColumnValue<int>(Columns.PhotoID); }
			set { SetColumnValue(Columns.PhotoID, value); }
		}
		  
		[XmlAttribute("GalleryID")]
		[Bindable(true)]
		public int GalleryID 
		{
			get { return GetColumnValue<int>(Columns.GalleryID); }
			set { SetColumnValue(Columns.GalleryID, value); }
		}
		  
		[XmlAttribute("Filename")]
		[Bindable(true)]
		public string Filename 
		{
			get { return GetColumnValue<string>(Columns.Filename); }
			set { SetColumnValue(Columns.Filename, value); }
		}
		  
		[XmlAttribute("Caption")]
		[Bindable(true)]
		public string Caption 
		{
			get { return GetColumnValue<string>(Columns.Caption); }
			set { SetColumnValue(Columns.Caption, value); }
		}
		  
		[XmlAttribute("Timestamp")]
		[Bindable(true)]
		public DateTime Timestamp 
		{
			get { return GetColumnValue<DateTime>(Columns.Timestamp); }
			set { SetColumnValue(Columns.Timestamp, value); }
		}
		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a PhotoGallery ActiveRecord object related to this Photo
		/// 
		/// </summary>
		public Impact.Model.Objects.PhotoGallery PhotoGallery
		{
			get { return Impact.Model.Objects.PhotoGallery.FetchByID(this.GalleryID); }
			set { SetColumnValue("GalleryID", value.GalleryID); }
		}
		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varGalleryID,string varFilename,string varCaption,DateTime varTimestamp)
		{
			Photo item = new Photo();
			
			item.GalleryID = varGalleryID;
			
			item.Filename = varFilename;
			
			item.Caption = varCaption;
			
			item.Timestamp = varTimestamp;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varPhotoID,int varGalleryID,string varFilename,string varCaption,DateTime varTimestamp)
		{
			Photo item = new Photo();
			
				item.PhotoID = varPhotoID;
			
				item.GalleryID = varGalleryID;
			
				item.Filename = varFilename;
			
				item.Caption = varCaption;
			
				item.Timestamp = varTimestamp;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn PhotoIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn GalleryIDColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn FilenameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn CaptionColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn TimestampColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string PhotoID = @"PhotoID";
			 public static string GalleryID = @"GalleryID";
			 public static string Filename = @"Filename";
			 public static string Caption = @"Caption";
			 public static string Timestamp = @"Timestamp";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
